<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>更改密码</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
	    <form class="layui-form">
	      <div class="layui-form-item">
	        <label class="layui-form-label">输入密码</label>
	        <div class="layui-input-block">
	          <input type="text" name="password" required="" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
	        </div>
	      </div>
	      <div class="layui-form-item">
	        <label class="layui-form-label">确认密码</label>
	        <div class="layui-input-block">
	          <input type="text" name="ensurepassword"  required="" lay-verify="required" placeholder="确认输入密码" autocomplete="off" class="layui-input">
	        </div>
	      </div>
	      <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit lay-filter="changePassword">立即提交</button>
              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
	  </form>
	
	
	    <script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script>
		    layui.use(['layer','form'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form;
		    	form.on('submit(changePassword)',function(data){
		    		if(data.field.password == data.field.ensurepassword){
		    			var username = "${sessionScope.Admintruename}";//要带双引号表示字符串
		    			$.ajax({
		    				type:'POST',
		    				url:'admin/changePassword',
		    				async:true,
		    				data:{username:username,password:data.field.password},
		    				success:function(resp){
		    					if(resp == "200"){
    							  $.ajax({
    									type:'POST',
    									url :'delete/out_catch',
    									async:true,
    									success:function(resp){
    										layer.msg("操作成功 ",{icon:1});
    										setTimeout(function (){
    											window.location.reload();
    										}, 1000)
    									},
    									error:function(){
    										layer.msg("操作失败 ",{icon:2});
    									}
    								}) 
		    					}else{
		    					  layer.msg("操作失败 ",{icon:2});
		    				      this.form.reset(); 
		    					}
		    				}
		    			});
		    		}else{
		    			layer.msg('密码不一致',{icon:2});
		    			this.form.reset();//清空form表单的值
		    		}
		    		return false;
		    	});
		    });
		</script>
    </body>
</html>